package com.hzh.cusviewdemo.Adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ObjectUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.hzh.cusviewdemo.Presenter.MusicCommentData;
import com.hzh.cusviewdemo.R;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.MyHolder> {

    private List<MusicCommentData.CommentData> dataList;
    private Context context;

    public CommentAdapter(List<MusicCommentData.CommentData> dataList, Context context) {
        this.dataList = dataList;
        this.context = context;
    }

    public void clearData() {
        dataList.clear();
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public CommentAdapter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull CommentAdapter.MyHolder holder, int position) {
        MusicCommentData.CommentData comment = dataList.get(position);

        Glide.with(context)
                .load(ObjectUtils.isNotEmpty(comment.getU_pic()) ? comment.getU_pic() : R.drawable.ic_logo_round)
                .into(holder.ic_avatar);
        holder.ic_name.setText(comment.getU_name());
        // 设置时间
        holder.ic_time.setText(comment.getTime());
        holder.ic_content.setText(comment.getMsg());

    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    static class MyHolder extends RecyclerView.ViewHolder {

        private CircleImageView ic_avatar;
        private TextView ic_name;
        private TextView ic_time;
        private TextView ic_content;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            ic_avatar = itemView.findViewById(R.id.ic_avatar);
            ic_name = itemView.findViewById(R.id.ic_name);
            ic_time = itemView.findViewById(R.id.ic_time);
            ic_content = itemView.findViewById(R.id.ic_content);
        }
    }
}
